home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / comm / tcp / rxsocket.lha / rxsocket / examples / dsfun.rexx < prev    next >
OS/2 REXX Batch file  |  2000-11-28  |  2KB  |  53 lines

  1. /*
  2. single connection handler for the ds service, see ds.rexx
  3. */
  4.  
  5. call initGlobal
  6. call getSocket
  7. call logConnection
  8. call handle
  9.  
  10. exit
  11. /***************************************************************************/
  12. initGlobal: procedure expose global.
  13.     global.prg=ProgramName()
  14.     call SysLogCtl(global.prg)
  15.     global.verbose=GetVar("VERBOSE","LOCAL")
  16.     if global.verbose="" then global.verbose=0
  17.     return
  18. /***************************************************************************/
  19. getSocket: procedure expose global.
  20.     global.sock=LastSocket()
  21.     if global.sock==-1 then do
  22.         call EasyRequest(global.prg "can only be started by ds with RXSCall",global.prg)
  23.         exit
  24.     end
  25.     return
  26. /***************************************************************************/
  27. handle: procedure expose global.
  28.     sel.read.0=global.sock
  29.     res = WaitSelect("SEL",10,0,2**12)
  30.     if res<0 then call err "err wait %m"
  31.     if res=0 then call err "timeout ("global.peer")"
  32.     if recv(global.sock,"BUFF",256)<0 then call err "error recv %m"
  33.     date=formatdate(,"%a, %d %b %Y %X")
  34.     if send(global.sock,date)<0 then call err "error send %m"
  35.     return
  36. /***************************************************************************/
  37. err: procedure expose global.
  38. parse arg msg
  39.     if global.verbose then call SysLog(msg,"ERR")
  40.     exit
  41. /***************************************************************************/
  42. info: procedure expose global.
  43. parse arg msg
  44.     if global.verbose then call SysLog(msg,"INFO")
  45.     return
  46. /***************************************************************************/
  47. logConnection: procedure expose global.
  48.     if GetPeerName(global.sock,"GLOBAL")<0 then call err "can't get peer info %m"
  49.     global.peer="<"global.addrAddr":"global.addrPort">"
  50.     if global.verbose then call info "connection from" global.peer
  51.     return
  52. /***************************************************************************/
  53.